home *** CD-ROM | disk | FTP | other *** search
/ Network PC / Network PC.iso / amiga utilities / communication / bbs / termv4.6 / extras / source / gtlayout-source.lha / LT_LockWindow.c < prev    next >
Encoding:
C/C++ Source or Header  |  1996-03-18  |  5.9 KB  |  285 lines

  1. /*
  2. **    GadTools layout toolkit
  3. **
  4. **    Copyright © 1993-1996 by Olaf `Olsen' Barthel
  5. **        Freely distributable.
  6. **
  7. **    :ts=4
  8. */
  9.  
  10. #ifndef _GTLAYOUT_GLOBAL_H
  11. #include "gtlayout_global.h"
  12. #endif
  13.  
  14.  
  15. /*****************************************************************************/
  16.  
  17.  
  18. VOID
  19. LTP_DeleteWindowLock(LockNode *Node)
  20. {
  21.     struct Window *Window = Node->Window;
  22.  
  23.     Remove((struct Node *)Node);
  24.  
  25.     if(Window->MinWidth == Window->MaxWidth && Window->MinHeight == Window->MaxHeight && Window->Width == Window->MaxWidth && Window->Height == Window->MaxHeight)
  26.         WindowLimits(Window,Node->MinWidth,Node->MinHeight,Node->MaxWidth,Node->MaxHeight);
  27.  
  28.     EndRequest(&Node->Requester,Window);
  29.  
  30.     if(V39)
  31.         SetWindowPointerA(Window,NULL);
  32.     else
  33.         ClearPointer(Window);
  34.  
  35.     ModifyIDCMP(Window,Node->OldIDCMPFlags);
  36.  
  37.     FreeMem(Node,sizeof(LockNode));
  38. }
  39.  
  40.  
  41. /*****************************************************************************/
  42.  
  43.  
  44. /****** gtlayout.library/LT_LockWindow ******************************************
  45. *
  46. *   NAME
  47. *    LT_LockWindow -- Block user access to a window.
  48. *
  49. *   SYNOPSIS
  50. *    LT_LockWindow(Window);
  51. *                    A0
  52. *
  53. *    VOID LT_LockWindow(struct Window *);
  54. *
  55. *   FUNCTION
  56. *    The window will get a wait mouse pointer attached and a blank
  57. *    Requester, preventing any user gadgets from getting used. The
  58. *    window minimum and maximum sizes are set to the current window
  59. *    size so the user will be unable to resize the window or click
  60. *    on the zoom gadget.
  61. *
  62. *    This routine nests, multiple calls to LT_LockWindow() using the
  63. *    same window will increment a usage counter, so exactly the
  64. *    same number of calls to LT_UnlockWindow() will be required to
  65. *    unlock the window.
  66. *
  67. *   INPUTS
  68. *    Window - Pointer to window structure; passign NULL is harmless.
  69. *
  70. *   RESULT
  71. *    none
  72. *
  73. *   NOTES
  74. *    Do not close the window you have locked unless all the
  75. *    outstanding locks are freed or memory will be lost which
  76. *    can never be reclaimed. Before you close the window,
  77. *    call gtlayout.library/LT_DeleteWindowLock.
  78. *
  79. *   SEE ALSO
  80. *    gtlayout.library/LT_DeleteWindowLock
  81. *
  82. ******************************************************************************
  83. *
  84. */
  85.  
  86. VOID LIBENT
  87. LT_LockWindow(_REG(a0) struct Window *window)
  88. {
  89.     if(window)
  90.     {
  91.         LockNode    *lockNode;
  92.         BOOL          found;
  93.  
  94.         found = FALSE;
  95.  
  96.         ObtainSemaphore(<P_LockSemaphore);
  97.  
  98.         SCANLIST(<P_LockList,lockNode)
  99.         {
  100.             if(lockNode->Window == window)
  101.             {
  102.                 lockNode->Count++;
  103.  
  104.                 found = TRUE;
  105.  
  106.                 break;
  107.             }
  108.         }
  109.  
  110.         if(!found)
  111.         {
  112.             if(lockNode = AllocMem(sizeof(LockNode),MEMF_PUBLIC | MEMF_ANY | MEMF_CLEAR))
  113.             {
  114.                 AddTail((struct List *)<P_LockList,(struct Node *)lockNode);
  115.  
  116.                 lockNode->Window        = window;
  117.                 lockNode->OldIDCMPFlags    = window->IDCMPFlags;
  118.                 lockNode->Count            = 1;
  119.                 lockNode->MinWidth        = window->MinWidth;
  120.                 lockNode->MaxWidth        = window->MaxWidth;
  121.                 lockNode->MinHeight        = window->MinHeight;
  122.                 lockNode->MaxHeight        = window->MaxHeight;
  123.  
  124.                 WindowLimits(window,window->Width,window->Height,window->Width,window->Height);
  125.  
  126.                 ModifyIDCMP(window,(window->IDCMPFlags & (IDCMP_REFRESHWINDOW|IDCMP_CHANGEWINDOW)) | IDCMP_SIZEVERIFY);
  127.  
  128.                 if(V39)
  129.                 {
  130.                     STATIC struct TagItem tags[3] =
  131.                     {
  132.                         WA_BusyPointer,        TRUE,
  133.                         WA_PointerDelay,    TRUE,
  134.  
  135.                         TAG_DONE
  136.                     };
  137.  
  138.                     SetWindowPointerA(window,tags);
  139.                 }
  140.                 else
  141.                 {
  142.                     STATIC UWORD __chip Stopwatch[(1 + 16 + 1) * 2] =
  143.                     {
  144.                         0x0000,0x0000,
  145.  
  146.                         0x0400,0x07C0,
  147.                         0x0000,0x07C0,
  148.                         0x0100,0x0380,
  149.                         0x0000,0x07E0,
  150.                         0x07C0,0x1FF8,
  151.                         0x1FF0,0x3FEC,
  152.                         0x3FF8,0x7FDE,
  153.                         0x3FF8,0x7FBE,
  154.                         0x7FFC,0xFF7F,
  155.                         0x7EFC,0xFFFF,
  156.                         0x7FFC,0xFFFF,
  157.                         0x3FF8,0x7FFE,
  158.                         0x3FF8,0x7FFE,
  159.                         0x1FF0,0x3FFC,
  160.                         0x07C0,0x1FF8,
  161.                         0x0000,0x07E0,
  162.  
  163.                         0x0000,0x0000
  164.                     };
  165.  
  166.                     SetPointer(window,Stopwatch,16,16,-6,0);
  167.                 }
  168.  
  169.                 Request(&lockNode->Requester,window);
  170.             }
  171.         }
  172.  
  173.         ReleaseSemaphore(<P_LockSemaphore);
  174.     }
  175. }
  176.  
  177.  
  178. /****************************************************************************/
  179.  
  180.  
  181. /****** gtlayout.library/LT_UnlockWindow ******************************************
  182. *
  183. *   NAME
  184. *    LT_UnlockWindow -- The complement to LT_LockWindow().
  185. *
  186. *   SYNOPSIS
  187. *    LT_UnlockWindow(Window);
  188. *                      A0
  189. *
  190. *    VOID LT_UnlockWindow(struct Window *);
  191. *
  192. *   FUNCTION
  193. *    This routine unlocks a window locked using LT_LockWindow, freeing
  194. *    allocated memory, restoring the window characteristics to their
  195. *    original values.
  196. *
  197. *   INPUTS
  198. *    Window - Pointer to window structure; passing NULL is harmless.
  199. *
  200. *   RESULT
  201. *    none
  202. *
  203. *   SEE ALSO
  204. *    gtlayout.library/LT_LockWindow
  205. *
  206. ******************************************************************************
  207. *
  208. */
  209.  
  210. VOID LIBENT
  211. LT_UnlockWindow(_REG(a0) struct Window *window)
  212. {
  213.     if(window)
  214.     {
  215.         LockNode *lockNode;
  216.  
  217.         ObtainSemaphore(<P_LockSemaphore);
  218.  
  219.         SCANLIST(<P_LockList,lockNode)
  220.         {
  221.             if(lockNode->Window == window)
  222.             {
  223.                 if(--lockNode->Count < 1)
  224.                     LTP_DeleteWindowLock(lockNode);
  225.  
  226.                 break;
  227.             }
  228.         }
  229.  
  230.         ReleaseSemaphore(<P_LockSemaphore);
  231.     }
  232. }
  233.  
  234.  
  235. /*****************************************************************************/
  236.  
  237.  
  238. /****** gtlayout.library/LT_DeleteWindowLock ******************************************
  239. *
  240. *   NAME
  241. *    LT_DeleteWindowLock -- Remove all locks from a window
  242. *
  243. *   SYNOPSIS
  244. *    LT_DeleteWindowLock(Window);
  245. *                          A0
  246. *
  247. *    VOID LT_DeleteWindowLock(struct Window *);
  248. *
  249. *   FUNCTION
  250. *    Before closing a locked window you should call this routine
  251. *    which will remove all outstanding locks from it.
  252. *
  253. *   INPUTS
  254. *    Window - Pointer to window structure; passing NULL is
  255. *    harmless.
  256. *
  257. *   RESULT
  258. *    none
  259. *
  260. ******************************************************************************
  261. *
  262. */
  263.  
  264. VOID LIBENT
  265. LT_DeleteWindowLock(_REG(a0) struct Window *window)
  266. {
  267.     if(window)
  268.     {
  269.         LockNode *lockNode;
  270.  
  271.         ObtainSemaphore(<P_LockSemaphore);
  272.  
  273.         SCANLIST(<P_LockList,lockNode)
  274.         {
  275.             if(lockNode->Window == window)
  276.             {
  277.                 LTP_DeleteWindowLock(lockNode);
  278.                 break;
  279.             }
  280.         }
  281.  
  282.         ReleaseSemaphore(<P_LockSemaphore);
  283.     }
  284. }
  285.